﻿//------------------------------------------------------------------------------
// ╭─────────────────────────────╮
// │ ╭─╮     ╭─╮              TM │   ╠═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╣
// │ │ │     │ │                 │                                           ☺  
// │ │ ╰───╮ │ │ ╭─────╮ ╭─────╮ │     Name:Wedn.Net 配置信息实体类      ♮ ♪ ♩
// │ │ ╭─╮ │ │ │ │ ╭─╮ │ │ ╭─╮ │ │                                    ♫ ♭      
// │ │ ╰─╯ │ │ │ │ ╰─╯ │ │ ╰─╯ │ │     Author:iceStone               ♬ ♪       
// │ └─────╯ └─╯ ╰─────╯ ╰───╮ │ │     Chinese:汪磊                              
// │                     ┌───╯ │ │                                              
// │                     ╰─────╯ │   ╠═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╣
// ╰─────────────────────────────╯                                              
//------------------------------------------------------------------------------
using System.Configuration;

namespace Wedn.Net.Common
{
    /// <summary>
    /// 配置信息实体类
    /// </summary>
    public class Config
    {
        /// <summary>
        /// 程序Url
        /// </summary>
        public static string SiteUrl
        {
            get
            {
                var siteUrl = "http://" + System.Web.HttpContext.Current.Request.Url.Host + SiteRoot;
                if (System.Web.HttpContext.Current.Request.Url.Port != 80)
                {
                    siteUrl = "http://" + System.Web.HttpContext.Current.Request.Url.Host + ":" + System.Web.HttpContext.Current.Request.Url.Port + SiteRoot;
                }
                return siteUrl;
            }
        }

        private static string _siteRoot;
        /// <summary>
        /// 程序相对根路径
        /// </summary>
        public static string SiteRoot
        {
            get
            {
                //避免装箱拆箱
                //string siteRoot = Application["SiteRoot"];
                if (string.IsNullOrEmpty(_siteRoot))
                {
                    _siteRoot = ConfigurationManager.AppSettings["SiteRoot"] ?? "/";
                }
                return _siteRoot;
            }
        }

        private static string _themeRoot;
        /// <summary>
        /// 主题皮肤所在根目录
        /// </summary>
        public static string ThemeRoot
        {
            get
            {
                if (string.IsNullOrEmpty(_themeRoot))
                {
                    _themeRoot = ConfigurationManager.AppSettings["ThemeRoot"] ?? "/Content/theme/";
                }
                return _themeRoot;
            }
        }

        private static string _uploadRoot;
        /// <summary>
        /// 文件上传根目录
        /// </summary>
        public static string UploadRoot
        {
            get
            {
                if (string.IsNullOrEmpty(_uploadRoot))
                {
                    _uploadRoot = ConfigurationManager.AppSettings["UploadRoot"] ?? "/Content/upload/";
                }
                return _uploadRoot;
            }
        }

        private static string _sitePrefix;
        /// <summary>
        /// Cache、Session、Cookies 等应用程序变量名前缀
        /// </summary>
        public static string SitePrefix
        {
            get
            {
                if (string.IsNullOrEmpty(_sitePrefix))
                {
                    _sitePrefix = ConfigurationManager.AppSettings["SitePrefix"] ?? "WEDN_";
                }
                return _sitePrefix;
            }
        }

        private static string _encryptKey;
        /// <summary>
        /// 加密密钥
        /// </summary>
        public static string EncryptKey
        {
            get
            {
                if (string.IsNullOrEmpty(_encryptKey))
                {
                    _encryptKey = ConfigurationManager.AppSettings["EncryptKey"] ?? "iceStone";
                }
                return _encryptKey;
            }
        }

        private static string _tablePrefix;
        /// <summary>
        /// 数据库表前缀
        /// </summary>
        public static string TablePrefix
        {
            get
            {
                if (string.IsNullOrEmpty(_tablePrefix))
                {
                    _tablePrefix = ConfigurationManager.AppSettings["TablePrefix"] ?? "W_";
                }
                return _tablePrefix;
            }
        }


        private static string _bllPath;
        /// <summary>
        /// 业务逻辑层程序集名称
        /// </summary>
        public static string BLLPath
        {
            get
            {
                if (string.IsNullOrEmpty(_bllPath))
                {
                    _bllPath = ConfigurationManager.AppSettings["BLLPath"] ?? "Wedn.Net.BLL";
                }
                return _bllPath;
            }
        }

        private static string _bllNameSpace;
        /// <summary>
        /// 业务逻辑层管理类命名空间
        /// </summary>
        public static string BLLNameSpace
        {
            get
            {
                if (string.IsNullOrEmpty(_bllNameSpace))
                {
                    _bllNameSpace = ConfigurationManager.AppSettings["BLLNameSpace"] ?? "Wedn.Net.BLL";
                }
                return _bllNameSpace;
            }
        }

        private static string _connectionString;
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                if (string.IsNullOrEmpty(_connectionString))
                {
                    _connectionString = ConfigurationManager.ConnectionStrings[ConfigurationManager.AppSettings["ConnStr"]].ConnectionString;
                }
                return _connectionString;
            }
        }

        private static string _dalPath;
        /// <summary>
        /// 数据库操作类组件名
        /// </summary>
        public static string DALPath
        {
            get
            {
                if (string.IsNullOrEmpty(_dalPath))
                {
                    _dalPath = ConfigurationManager.AppSettings["DALPath"] ?? "Wedn.Net.SQLServerDAL";
                }
                return _dalPath;
            }
        }

        private static string _dalNameSpace;
        /// <summary>
        /// 数据库操作类命名空间
        /// </summary>
        public static string DALNameSpace
        {
            get
            {
                if (string.IsNullOrEmpty(_dalNameSpace))
                {
                    _dalNameSpace = ConfigurationManager.AppSettings["DALNameSpace"] ?? "Wedn.Net.DAL";
                }
                return _dalNameSpace;
            }
        }
    }
}
